package com.furtherstar.auth.util;

import com.furtherstar.auth.dao.model.UserSecret;
import com.yummy.convention.encrypt.Encrypt;

public class PasswordUtil {
	
	public final static String passwordSalt = "1960oiILl1";

	public static String encryptPassword(String password, String salt) {
		return Encrypt.MD5(password+passwordSalt+salt);
	}

	public static boolean checkPassword(String credential, UserSecret userSecret) {
		String realPassword = userSecret.getPassword();
		if(realPassword == null) {
			return false;
		}
		String salt = userSecret.getUserid().toString();
		return checkPassword(realPassword,salt,credential);
	}

	private static boolean checkPassword(String realPassword, String salt, String credential) {
		return realPassword.equals(Encrypt.MD5(credential+passwordSalt+salt));
	}
	
	public static void main(String[] args) {
		System.out.println(Encrypt.MD5("123456"+passwordSalt+"2"));
	}

}
